﻿using System.Configuration;
using System.Reflection;

namespace RDIFramework.ServiceAdapter
{
    using RDIFramework.IService;

    /// <summary>
    /// RDIFrameworkServiceFactory
    /// 
    /// 修改纪录
    /// 
    ///		2012.03.01 版本：1.0 EricHu 创建。
    ///		
    /// 版本：1.0
    ///
    /// <author>
    ///		<name>EricHu</name>
    ///		<date>2012.03.01</date>
    /// </author> 
    /// </summary>
    public abstract class RDIFrameworkServiceFactory
    {
        private static readonly string servicePath = ConfigurationManager.AppSettings["Service"];
        private static readonly string serviceFactoryClass = ConfigurationManager.AppSettings["ServiceFactory"];
        
        public RDIFrameworkServiceFactory() 
        {
        }

        public IServiceFactory GetServiceFactory()
        {
            return GetServiceFactory(servicePath);
        }

        public IServiceFactory GetServiceFactory(string servicePath)
        {
            string className = servicePath + "." + serviceFactoryClass;
            return (IServiceFactory)Assembly.Load(servicePath).CreateInstance(className);
        }

        public IServiceFactory GetServiceFactory(string servicePath, string serviceFactoryClass)
        {
            string className = servicePath + "." + serviceFactoryClass;
            return (IServiceFactory)Assembly.Load(servicePath).CreateInstance(className);
        }
    }
}